package com.lei.cmsservice.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lei.cmsservice.entity.CrmBanner;
import com.lei.cmsservice.service.CrmBannerService;
import com.lei.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 * @author 熊磊
 * @since 2020-06-11
 */
@RestController
@RequestMapping("/edu/banneradmin")
public class BannerAdminController {
    @Autowired
    private CrmBannerService bannerService;

    //根据Id获取
    @GetMapping("/{id}")
    public Result getBannerById(@PathVariable("id") String id){
        return Result.ok().data("banner",bannerService.getById(id));
    }

    //分页查询
    @GetMapping("/pageBanner")
    public Result pageBanner(@PathVariable("current") Long current,@PathVariable("limit") Long limit){
        //page对象
        Page<CrmBanner> page = new Page<>(current,limit);

        bannerService.page(page);

        return Result.ok().data("records",page.getRecords()).data("total",page.getTotal());
    }
    //添加banner
    @PostMapping("/addBanner")
    public Result addBanner(@RequestBody CrmBanner banner){
        bannerService.saveBanner(banner);
        return Result.ok();
    }
    //修改banner
    @PostMapping("/updateBanner")
    public Result updateBanner(@RequestBody CrmBanner banner){
        bannerService.updateBannerById(banner);
        return Result.ok();
    }
    //删除banner
    @DeleteMapping("/deleteBanner/{id}")
    public Result deleteBanner(@PathVariable("id") String id){
        bannerService.removeBannerById(id);
        return Result.ok();
    }
}

